package org.lex.ftplist.core.visitors;

import org.apache.commons.net.ftp.FTPFile;
import org.lex.collection.tree.ITreeNode;
import org.lex.collection.tree.ITreeVisitor;

public class StatisticVisitor implements ITreeVisitor {
	private Statistic stat = new Statistic();

	public Statistic getStatistic() {
		return stat;
	}

	@Override
	public void visit(ITreeNode node) {
		FTPFile file = (FTPFile) node.getData();
		if (null != file) {
			if (file.isFile()) {
				stat.fileCount++;
				stat.size += file.getSize();
			}
			if (file.isDirectory()) {
				stat.folderCount++;
			}
		}
	}
}
